<template>
	<sc-dialog
		v-model="visible"
		show-fullscreen
		class="column-dialog"
		:title="titleMap[mode]"
		width="650px"
		@close="close"
	>
		<scTable
			ref="table"
			:api-obj="apiObj"
			:column="column"
			:params="params"
			row-key="id"
			:hidePagination="true"
			:hideDo="true"
			@selection-change="selectionChange"
		>
			<!-- 固定列-选择列 -->
			<el-table-column
				label="#"
				type="index"
				width="50"
			></el-table-column>
			<el-table-column
				align="center"
				fixed="right"
				label="操作"
				width="100"
			>
				<template #default="scope">
					<el-popconfirm
						title="确定删除吗？"
						@confirm="table_del(scope.row, scope.$index)"
					>
						<template #reference>
							<el-button text type="primary" size="small">删除</el-button>
						</template>
					</el-popconfirm>
				</template>
			</el-table-column>
			<template #wxName="{ data }">
				<el-avatar
					class="user-avatar"
					size="small"
					:src="resHead(data)"
				/>{{ data.wxName }}
			</template>
		</scTable>
		<template #footer>
			<el-button @click="close">关闭查看</el-button>
		</template>
	</sc-dialog>
</template>
<script>
export default {
	data() {
		return {
			mode: "look",
			titleMap: {
				look: "内定用户",
			},
			visible: false,
			apiObj: this.$API.member.page,
			params: {},
			column: [
				{
					label: "id",
					prop: "id",
					width: "200",
					sortable: true,
					hide: true,
				},
				{ prop: "wxName", label: "微信昵称", align: "left" },
				{ prop: "mobile", label: "手机号码", width: 120 },
				{ prop: "createTime", label: "注册时间", width: 180 },
			],
			delParam: {
				prizeId: "0",
				userId: "0",
				info: {},
			},
			userIds: [],
		};
	},
	methods: {
		open(m, id) {
			this.delParam.prizeId = id;
			this.delParam.info = m;
			this.visible = true;
			this.userIds = m.users;
			this.params = { userIds: m.users.join(",") };
			if (this.$refs.table) {
				this.$refs.table.upData({ userIds: m.users.join(",") });
			}
		},
		resHead(data) {
			if (!data.headPic && data.headPic.indexOf("http") == -1) {
				data.headPic = this.$CONFIG.SERVER_URL + data.headPic;
			}
			return data.headPic;
		},
		async table_del(row) {
			this.delParam.userId = row.id;
			var res = await this.$API.carsprize.internal.delete(this.delParam);
			if (res.code == 200) {
				this.delArr(row.id);
				if (this.userIds.length == 0) {
					this.$refs.table.upData({ userIds: 0 });
				} else {
					this.$refs.table.upData({
						userIds: this.userIds.join(","),
					});
				}

				this.$message.success("删除成功");
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		},
		delArr(item) {
			for (let i = 0; i < this.userIds.length; i++) {
				if (this.userIds[i] == item) {
					this.userIds.splice(i, 1);
				}
			}
		},
		close() {
			this.visible = false;
		},
	},
};
</script>
<style lang="scss" scoped>
.user-avatar {
	vertical-align: middle;
	margin-right: 5px;
}
</style>
